package net.web.inst.struts2;

import java.util.List;

import javax.annotation.Resource;

import net.esj.basic.utils.StringUtils;
import net.melon.article.ArticleConstants;
import net.melon.product.pojo.Product;
import net.melon.uploader.Uploader;
import net.web.dto.City;
import net.web.dto.ParamArticle;
import net.web.dto.ParamDto;
import net.web.dto.ProductDto;
import net.web.dto.UnicodeParamDto;
import net.web.inst.service.WebService;


public class IndexAction extends WebAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3864274860663240783L;
	
	@Resource
	private WebService webService;
	
	
	public String index(){
		setResultUrl("index/main");
		return SUCCESS;
	}
	
	public String prodlist(){
		setResultUrl("product/list");
		return SUCCESS;
	}
	

	
	public String proddetails(){
		setResultUrl("product/details");
		return SUCCESS;
	}

	
	public String proddeal(){
		setResultUrl("product/deal");
		return SUCCESS;
	}

	
	public String paysucc(){
		setResultUrl("pay/success");
		return SUCCESS;
	}

	
	public String payfail(){
		setResultUrl("pay/fail");
		return SUCCESS;
	}
	

	public String orderlist(){
		setResultUrl("user/order-list");
		return SUCCESS;
	}

	public String review(){
		setResultUrl("user/review");
		return SUCCESS;
	}

	public String book(){
		setResultUrl("user/book");
		return SUCCESS;
	}
	

	public String newslist(){
		setResultUrl("news/list");
		return SUCCESS;
	}
	

	public String newsdetails(){
		setResultUrl("news/details");
		return SUCCESS;
	}


	public String activitylist(){
		setResultUrl("activity/list");
		return SUCCESS;
	}

	public String aboutus(){
		setResultUrl("html/aboutus");
		return SUCCESS;
	}

	public String agree(){
		setResultUrl("html/agree");
		return SUCCESS;
	}

	public String contact(){
		setResultUrl("html/contact");
		return SUCCESS;
	}

	public String culture(){
		setResultUrl("html/culture");
		return SUCCESS;
	}

	public String partner(){
		setResultUrl("html/partner");
		return SUCCESS;
	}

	public String process(){
		setResultUrl("html/process");
		return SUCCESS;
	}

	public String takecar(){
		setResultUrl("html/takecar");
		return SUCCESS;
	}

	public String problem(){
		setResultUrl("html/problem");
		return SUCCESS;
	}
	

	public String examine(){
		setResultUrl("examine/main");
		return SUCCESS;
	}
	

	public String lease(){
		setResultUrl("lease/details");
		return SUCCESS;
	}
	
	public String paySuccess(){
		setResultUrl("pay/success");
		return SUCCESS;
	}
	
	public String payFail(){
		setResultUrl("pay/fail");
		return SUCCESS;
	}
	
	/**
	 * 获取城市
	 * */
	public List<City> getCityList(){
		List<City> list = webService.getCityList();
		return list;
	}
	
	/**广告*/
	public List<ParamDto> getAdvList(){
		List<ParamDto> dtos = webService.getAdvList();
		return dtos;
	}
	/**品牌*/
	public List<UnicodeParamDto> getBrandList(){
		List<UnicodeParamDto> dtos = webService.getBrandList();
		return dtos;
	}
	/**活动*/
	public List<ParamDto> getHotActivityList(){
		List<ParamDto> dtos = webService.getHotActivityList(true);
		return dtos;
	}
	/**热门车型*/
	public List<ProductDto> getHotCarList(){
		List<ProductDto> dtos = webService.getHotCarList(getCitySession());
		for(ProductDto dto : dtos){
			if(StringUtils.hasText(dto.getIcon())){
				dto.setIcon(Uploader.getDownUrl(Product.ICON_SUB_DIR) + dto.getIcon());
			}
		}
		return dtos;
	}
	/**新闻资讯*/
	public List<ParamArticle> getNewsInformationList(){
		List<ParamArticle> dtos = webService.getNewsInformationList();
		for(ParamArticle dto : dtos){
			dto.getArticle().setIcon(Uploader.getDownUrl(ArticleConstants.ARTICLE_CONTENT_ICON_UPLOAD_KEY)+dto.getArticle().getIcon());
		}
		return dtos;
	}
	/**印象够买*/
	public List<ParamArticle> getBuyPurchaseList(){
		List<ParamArticle> dtos = webService.getBuyPurchaseList();
		for(ParamArticle dto : dtos){
			dto.getArticle().setIcon(Uploader.getDownUrl(ArticleConstants.ARTICLE_CONTENT_ICON_UPLOAD_KEY)+dto.getArticle().getIcon());
		}
		return dtos;
	}
	
	/**以租代购*/
	public void getCarLeaseList(){
		try {
			List<ParamArticle> dtos = webService.getCarLeaseList();
			for(ParamArticle dto : dtos){
				dto.getArticle().setIcon(Uploader.getDownUrl(ArticleConstants.ARTICLE_CONTENT_ICON_UPLOAD_KEY)+dto.getArticle().getIcon());
			}
			writeJson(dtos);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
